home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / T U R B O Language / Turbo C Tools v6.0 / EXAMPLES / NORMFILE.C < prev    next >
Encoding:
C/C++ Source or Header  |  1989-03-31  |  3.3 KB  |  103 lines

  1. /*
  2. *    NORMFILE.C    Exhibit normalization of files.
  3. *
  4. *  The purpose of NORMFILE is to show just exactly what is meant
  5. *  by the normalization of a file name.
  6. *
  7. *  This program displays a prompt on the screen, asking for a
  8. *  filename to normalize.  If the user presses just ENTER, he is
  9. *  returned to DOS.  If the user types a string, it is normalized
  10. *  into a filename, and then the user is prompted for another
  11. *  filename.
  12. *
  13. *  The command line format is as follows:
  14. *
  15. *    normfile
  16. *
  17. *  Version    6.00 (C)Copyright Blaise Computing Inc. 1987-1989
  18. *
  19. */
  20.  
  21.  
  22. #include <stdio.h>
  23.  
  24. #include <bfiles.h>
  25.  
  26. #define NUL '\0'
  27.  
  28. static char *descrip[] =
  29. {
  30.     "NORMFILE normalizes file names.  Normalization means:", "",
  31.     "    1) Detecting all illegal characters, including extra periods ('.'),",
  32.     "       slashes ('/'), backslashes ('\\'), etc.;",
  33.     "    2) Converting all letters to lower case;",
  34.     "    3) Converting all slashes to backslashes;",
  35.     "    4) Removing the trailing colon (':') from a possible device name;",
  36.     "    5) Adding the current disk drive name (if no disk drive is named);",
  37.     "    6) Adding the full path from the root directory if it is absent;",
  38.     "    7) Resolving \".\" and \"..\";",
  39.     "    8) Truncating each portion of the path name to eight characters",
  40.     "       + dot + three characters; and",
  41.     "    9) Removing the dot from each portion of the path name where it",
  42.     "       is redundant.", "",
  43.     "This does not include:","",
  44.     "    1) Checking the existence of any portion of the path, or",
  45.     "    2) Checking for the presence of a possible device (if a trailing",
  46.     "       colon is found).",
  47.     "",
  48.     NIL
  49. };
  50.  
  51. void main (void)
  52. {
  53.     char  filename [80];
  54.     char  normname [80];
  55.     char *pdescrip;
  56.     int   i = 0;
  57.     int   lastpart;
  58.     int   errcode;
  59.  
  60.         /* Print out description                */
  61.     for (i = 0,  pdescrip = descrip[0];
  62.      pdescrip != NIL;
  63.      i++, pdescrip = descrip [i])
  64.     puts (pdescrip);
  65.  
  66.     printf ("press ENTER for some examples: ");
  67.     gets (filename);
  68.  
  69.         /* Show some examples of file normalization.        */
  70.     errcode = flnorm ("a:\\z.", normname, &lastpart);
  71.     printf ("  original      =<%s>\n",  "a:\\z.");
  72.     printf ("  normalization =<%s>\n",  normname);
  73.     printf ("  filename      =<%s>\n",  &(normname [lastpart]));
  74.     printf ("  errcode       = %d\n\n", errcode);
  75.  
  76.     errcode = flnorm ("..\\zap\\v.1234", normname, &lastpart);
  77.     printf ("  original      =<%s>\n",  "..\\zap\\v.1234");
  78.     printf ("  normalization =<%s>\n",  normname);
  79.     printf ("  filename      =<%s>\n",  &(normname [lastpart]));
  80.     printf ("  errcode       = %d\n\n", errcode);
  81.  
  82.     printf ("\nfile to normalize -- ENTER to quit?\n\n");
  83.  
  84.     do
  85.     {
  86.         /* Get a filename, or ENTER to terminate.        */
  87.     printf ("original        = ");
  88.     gets (filename);
  89.  
  90.         /* If we were not asked to terminate, go do the     */
  91.         /* normalization.                    */
  92.     if (filename [0] != NUL)
  93.     {
  94.         errcode = flnorm (filename, normname, &lastpart);
  95.  
  96.         /* Show what FLNORM returned to the user.        */
  97.         printf ("  normalization =<%s>\n",  normname);
  98.         printf ("  filename      =<%s>\n",  &(normname [lastpart]));
  99.         printf ("  errcode       = %d\n\n", errcode);
  100.     }
  101.     } while (filename [0] != NUL);
  102. }
  103.